﻿using DictManage.Code;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DictManage
{
    public partial class FrmManageDictList : Form
    {
        public FrmManageDictList(string dicttypeId, string dicttypeName)
        {
            InitializeComponent();
            this.txt_DictTypeID.Text = dicttypeId;
            this.txt_DictTypeName.Text = dicttypeName;
            this.txt_DictTypeName.Enabled = false;
            //this.label6.Visible = false;
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            string m_Id = Guid.NewGuid().ToString();
            string m_DtId = this.txt_DictTypeID.Text;
            string m_Context = this.txt_Context.Text;

            string[] txtRows = m_Context.Split(Environment.NewLine.ToArray());
            int count = 1;
            for (int i = 0; i < txtRows.Length; i++)
            {
                if (!string.IsNullOrWhiteSpace(txtRows[i]))
                {
                    string m_Seq = count.ToString();
                    string m_Name = txtRows[i];
                    string m_Value = txtRows[i];
                    string m_Remark = "";

                    if (txtRows[i].IndexOf('=') > 0)
                    {
                        string[] strAll = txtRows[i].Split('=');
                        m_Name = strAll[0];
                        m_Value = strAll[1];
                    }
                    string sql = @"INSERT INTO [TB_DictData]([ID],[DictType_ID],[Name],[Value],[Remark],[Seq],[Editor],[LastUpdated])
                     VALUES ('" + Guid.NewGuid() + "','" + m_DtId + "','" + m_Name + "','" + m_Value + "','" + m_Remark + "','" + m_Seq + "','','" + DateTime.Now.ToString() + "')";
                    OleDbAccess.ExecuteNonQury(sql);
                    count++;
                }
            }
            this.txt_Context.Text = "";
            MessageBox.Show("批量添加成功...");
            this.Close();
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
